<template>
  <div>
    <div
      class="house-item"
      @click="goToDetail(item.house_id)"
      v-for="item in list"
      :key="item.house_id"
    >
      <el-image class="house-post" :src="item.post" lazy></el-image>
      <div class="title">{{item.title}}</div>
      <div class="labels" v-if="item.labels">
        <span v-for="label in item.labels.split(',')" :key="label">{{label}}</span>
      </div>
      <div class="price-row">
        <span class="price">¥ {{item.price}}</span> 每晚
      </div>
    </div>
  </div>
</template>



<script>
export default {
  name: "Home",
  components: {},
  data() {
    return {
      // screenHeight: document.documentElement.clientHeight + "px",
      list: []
    };
  },
  created() {
    this.getHouseList();
  },
  methods: {
    getHouseList() {
      const _this = this;
      this.$axios
        .get("/house/getHouses", {
          params: {
            pageNo: 1
          }
        })
        .then(function(res) {
          console.log("列表", res);
          if (res.status == 200) {
            _this.list = res.data;
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    goToDetail(id) {
      console.log("id", id);
      this.$router.push({ path: "/detail", query: { id: id } });
    }
  }
};
</script>

<style>
* {
  text-align: left;
}

.title {
  font-weight: 500;
}
.labels {
  margin: 5px 0 10px 0;
}
.labels span {
  border: 1px solid darkcyan;
  border-radius: 5px;
  padding: 3px 5px;
  margin-right: 5px;
  font-size: 12px;
  color: darkcyan;
}
.post-img {
  height: 100%;
  width: auto;
}

@media screen and (min-width: 900px) {
  .house-item {
    width: 30.6%;
    float: left;
    margin-left: 2%;
    height: 420px;
    cursor: pointer;
  }
}

@media screen and (min-width: 500px) and (max-width: 899px) {
  .house-item {
    width: 45%;
    float: left;
    margin-left: 2%;
    height: 420px;
    cursor: pointer;
  }
}

@media screen and(max-width: 499px) {
  .house-item {
    width: 100%;
    margin: 15px 2%;
    height: 420px;
    cursor: pointer;
  }
}

.house-post {
  width: 100%;
  height: 280px;
}

.home-bg {
  overflow: hidden;
  width: 100%;
}

.price-row {
  font-size: 14px;
  color: #ccc;
}

.price {
  color: tomato;
  margin-right: 5px;
}
</style>